/*
** op.h for corewar in /home/vanet_c//proj-kw
** 
** Made by nicolas sadirac
** 
** Started on  Tue JUL 13 18:53:48 1993 nicolas sadirac
** Last update Sat Dec 15 12:39:31 2012 charles-edouard vanet
*/

#ifndef		_OP_H_
# define	_OP_H_

/*
**	IDX_MOD " modulo de l'index < "
**	MAX_ARG_NUMBER " this may not be changed 2^*IND_SIZE "
*/
# define	MEM_SIZE	(6*1024)
# define	IDX_MOD		512
# define	MAX_ARGS_NUMBER	4

# define	COMMENT_CHAR	'#'
# define	LABEL_CHAR	':'
# define	DIRECT_CHAR	'%'
# define	SEPARATOR_CHAR	','

# define LABEL_CHARS		"abcdefghijklmnopqrstuvwxyz_0123456789"

# define NAME_CMD_STRING	".name"
# define COMMENT_CMD_STRING	".comment"

/*
** regs
**	REG_NUMBER " r1 <--> rx "
*/
# define	REG_NUMBER	16

/*
**	T_REG " registre "
**	T_DIR " directe  (ld  #1,r1  met 1 dans r1) "
**	T_IND " indirecte toujours relatif ( ld 1,r1 met ce qu'il y a l'adress (1+pc) dans r1 (4 octecs ))"
**	T_LAB " LABEL " 
*/
typedef char	args_type_t;

# define	T_REG	1
# define	T_DIR	2
# define	T_IND	4
# define	T_LAB	8

typedef struct	op_s
{
  char		*mnemonique;
  char		nbr_args;
  args_type_t	type[MAX_ARGS_NUMBER];
  char		code;
  int		nbr_cycles;
  char		*comment;
}		op_t;

/*
** size
**	les SIZE sont en octets
*/

# define	IND_SIZE	2
# define	REG_SIZE	4
# define	DIR_SIZE	REG_SIZE

/*
** op_tab
*/
extern op_t	op_tab[];

/*
** header
*/
# define	PROG_NAME_LENGTH	128
# define	COMMENT_LENGTH		2048
# define	COREWAR_EXEC_MAGIC	0xea83f3

typedef struct	header_s
{
  int		magic;
  char		prog_name[PROG_NAME_LENGTH+1];
  int		prog_size;
  char		comment[COMMENT_LENGTH+1];
}		header_t;

/*
** live 
**	CYCLE_TO_DIE " nombre de cycle pour etre d\'eclarer mort "
*/
# define	CYCLE_TO_DIE	1536
# define	CYCLE_DELTA	5
# define	NBR_LIVE	40

#endif
